home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / pcc12d.zip / PCIO.A < prev    next >
Text File  |  1988-11-29  |  13KB  |  577 lines

  1. ;    PCIO.A    --    Screen and keyboard interface routines for the PC
  2.  
  3.  
  4.         dseg
  5. ;    In this implementation, all special and function keys are translated
  6. ;    to the following values.
  7.  
  8. ;/* control key translations */
  9. up_char        equ    30
  10. down_char    equ    31
  11. left_char    equ    29
  12. right_char    equ    28
  13. bol_char    equ    200
  14. eol_char    equ    201
  15. pageup_char    equ    202
  16. pagedown_char    equ    203
  17. bof_char    equ    204
  18. eof_char    equ    205
  19. Ins_char    equ    206
  20. Del_char    equ    207
  21. NextWord_char    equ    208
  22. PrevWord_char    equ    209
  23.  
  24. M1        equ    210
  25. M2        equ    211
  26. M3        equ    212
  27. M4        equ    213
  28. M5        equ    214
  29. M6        equ    215
  30. M7        equ    216
  31. M8        equ    217
  32. M9        equ    218
  33. M10        equ    219
  34. ;    the table that is used to make the translation
  35.  
  36. convert:
  37.         db    72, up_char
  38.         db    80, down_char
  39.         db    75, left_char
  40.         db    77, right_char
  41.         db    71, bol_char
  42.         db    79, eol_char
  43.         db    73, pageup_char
  44.         db    81, pagedown_char
  45.         db    77H, bof_char
  46.         db    75H, eof_char
  47.         db    82, Ins_char
  48.         db    83, Del_char
  49.         db    115, PrevWord_char
  50.         db    116, NextWord_char
  51.         db    59, M1
  52.         db    60, M2
  53.         db    61, M3
  54.         db    62, M4
  55.         db    63, M5
  56.         db    64, M6
  57.         db    65, M7
  58.         db    66, M8
  59.         db    67, M9
  60.         db    68, M10
  61.         db    0, 255 ; illegal character
  62.  
  63. ;    equates for bios interface.
  64.  
  65. ;    the interrupt and codes for the screen interface interrupt.
  66.  
  67. video        equ    10h        ;interrupt for dealing with screen
  68.  
  69. mode        equ    0        ;code for setting new screen mode
  70. curtype        equ    1        ;code for setting new cursor type
  71. setcur        equ    2        ;code for addressing cursor
  72. readcur        equ    3        ;code for reading cursor location
  73. readlp        equ    4        ;code for reading light pen position
  74. setpage        equ    5        ;code to select active page
  75. scrollup    equ    6        ;code to scroll screen up
  76. scrolldn    equ    7        ;code to scroll screen nown
  77. readch        equ    8        ;code to read a character from screen
  78. writeach    equ    9        ;code to write char and attributes
  79. writech        equ    10        ;code to write character only
  80. setpal        equ    11        ;code to set new setpal or border
  81. wdot        equ    12        ;code to write a dot
  82. rdot        equ    13        ;code to read a dot
  83. wtty        equ    14        ;code to write as if teletype
  84. state        equ    15        ;code to find current screen status
  85.  
  86.  
  87.  
  88. ;    the interrupt and codes for the keyboard interface.
  89.  
  90. keyboard    equ    16h        ;interrupt 16 to deal with keyboard
  91.  
  92. cicode        equ    0        ;code for reading a character
  93. cstscode    equ    1        ;code for keyboard status
  94.  
  95.  
  96.  
  97.  
  98. ;    caution: must change column number if 40 column mode
  99.  
  100. crt_cols    equ    80
  101.  
  102. ;    variables available to a C88 program
  103.  
  104.         public    scr_cols_, scr_rows_, scr_scrollup_, scr_scrolldown_    
  105.         public    scr_mode_,scr_page_,scr_attr_,scr_window_top_
  106.  
  107. scr_cols_:    dw    crt_cols    ;current number of columns
  108.  
  109. ;    note- make 25 for ms-dos and 24 for cp/m as cp/m steals the bottom
  110. ;    line.
  111. scr_rows_:    dw    25        ;current number of rows
  112. scr_mode_    db    0        ;current screen mode
  113. scr_page_    db    0        ;current page
  114. scr_attr_    db    7        ;current attributes for screen
  115.                     ;7 is white letters on black
  116. scr_window_top_    db    2        ;first line to scroll
  117.  
  118. ;    variables needed by SEE. Not used here.
  119. scr_scrollup_:    db    0        ;zero if scrollup leaves top line alone
  120. scr_scrolldown_:db    0        ;zero if scroll down supported
  121.  
  122.  
  123.  
  124.         cseg
  125.  
  126. ;    SCR_SETUP_    scr_setup must be called before any use of any
  127. ;            other routine unless the starting mode is 80X25
  128. ;            character mode (3,4 or 7). Must be called for monocrome
  129. ;            (mode 7) for scr_curson to set a proper cursor.
  130.  
  131. ;            Usage:    scr_setup();
  132.  
  133.         public    scr_setup_
  134. scr_setup_:    push    bp
  135.         mov    ah,state        ;get current state
  136.         int    video
  137.         mov    scr_mode_,al        ;current mode
  138.         mov    cl,ah            ;make cols a word
  139.         mov    ch,0
  140.         mov    scr_cols_,cx        ;40 or 80 columns
  141.         mov    scr_page_,bh
  142.         mov    scr_attr_,7        ;set to white chars on black
  143.         cmp    al,4            ;see if a character mode
  144.         jc    got_attr
  145.         cmp    al,7            ;7 is for graphics mode
  146.         jz    got_attr
  147.         mov    scr_attr_,0        ;attribute is zero in graphics
  148. got_attr:    mov    ah,0            ;return int containing mode
  149.         pop    bp
  150.         ret
  151.  
  152.  
  153. ;    SCR_TERM_        do any required termination.
  154.  
  155. ;                Usage:  scr_term();
  156.  
  157.     public    scr_term_
  158. scr_term_:
  159.     ret
  160.  
  161.  
  162.  
  163.  
  164.  
  165. ;    SCR_SETMODE_        set a new screen mode
  166.  
  167. ;                Usage:    scr_setmode(new mode);
  168.  
  169.         public    scr_setmode_
  170. scr_setmode_:    push    bp
  171.         mov    bp,sp
  172.         mov    al,[bp+4]    ; new mode value
  173.         mov    ah,mode
  174.         int    video        ; set new mode
  175.         call    scr_setup_    ;remember new values
  176.         pop    bp
  177.         ret
  178.  
  179.  
  180. ;    SCR_ROWCOL_        sets cursor at any location.
  181.  
  182. ;                Usage:    scr_rowcol(new row, new column);
  183.  
  184.         public    scr_rowcol_
  185. scr_rowcol_:                ; move cursor to x,y
  186.         push    bp        ; save from bios
  187.         mov    bp,sp
  188.         mov    dx,[bp+6]    ; column
  189.         mov    ax,[bp+4]    ; row
  190.         mov    dh,al
  191.         mov    bh,scr_page_    ; force page zero
  192.         mov    ah,setcur    ; set cursor location
  193.         int    video        ; call bios
  194.         pop    bp
  195.         ret
  196.  
  197.  
  198. ;    SCR_CLR_        clear entire screen
  199.  
  200. ;                Usage:    scr_clr();
  201.  
  202.         public    scr_clr_
  203. scr_clr_:                ; clear screen
  204.  
  205.  
  206.         push    bp        ;save from video call
  207.         mov    al,0        ;ask for a clear window
  208.         xor    cx,cx        ;start at 0,0
  209.         mov    dh,byte scr_rows_;last line
  210.         dec    dh
  211.         mov    dl,byte scr_cols_    ;clear entire width
  212.         dec    dl        ;last column is width-1
  213.         mov    bh,scr_attr_    ;attributes for new blanks
  214.         mov    ah,scrollup    ;ask for a scrollup to clear
  215.         int    video        ;do the clear
  216.         pop    bp
  217.         ret
  218.  
  219.  
  220.  
  221. ;    SCR_CLRL_        clear rest of line.
  222.  
  223. ;                Usage:        scr_clrl();
  224.  
  225.         public    scr_clrl_        
  226. scr_clrl_:                ; clear rest of line
  227.         push    bp
  228.         mov    bh,scr_page_
  229.         mov    ah,readcur    ;see where we are
  230.         int    video
  231.         mov    cl,byte scr_cols_    ;calc how many chars left in line
  232.         sub    cl,dl        ;number left
  233.         mov    ch,0        ;number of blanks needed
  234.         mov    al,' '        ;write blanks
  235.         mov    bl,scr_attr_    ;normal attributes
  236.         mov    bh,scr_page_    ;page number
  237.         mov    ah,writeach    ;write the blanks
  238.         int    video
  239.         pop    bp
  240.         ret
  241.  
  242.  
  243. ;    SCR_CLS_        clear rest of screen.
  244.  
  245. ;                Usage:    scr_cls();
  246.  
  247.         public    scr_cls_
  248. scr_cls_:                    ; clear rest of screen
  249.         push    bp
  250.         call    scr_clrl_    ;clear rest of line
  251.         mov    ah,readcur    ;see where we are
  252.         mov    bh,scr_page_
  253.         int    video
  254.         mov    al,0        ;ask for a clear window
  255.         mov    ch,dh        ;current row
  256.         inc    ch        ;+1
  257.         cmp    ch,byte scr_rows_;see if in last line
  258.         jz    cleared        ;all done
  259.         mov    cl,0        ;first column
  260.         mov    dh,byte scr_rows_;24 is the last line
  261.         dec    dh
  262.         mov    dl,byte scr_cols_    ;clear entire width
  263.         dec    dl        ;last column is width-1
  264.         mov    bh,scr_attr_    ;attributes for new blanks
  265.         mov    ah,scrollup    ;ask for a scrollup to clear
  266.         int    video        ;do the clear
  267. cleared:    pop    bp
  268.  
  269.         ret
  270.  
  271.  
  272.  
  273. ;    SCR_SCUP_        scroll text up leaving top lines alone.
  274.  
  275. ;                Usage:    scr_scup();
  276.  
  277.         public    scr_scup_
  278. scr_scup_:            ; scroll last line, screen from line
  279.                 ; scr_windor_top to end
  280.         mov    ax,scr_cols_    ;need last column of screen
  281.         dec    ax
  282.         push    ax
  283.         mov    ax,scr_rows_    ;scroll through last line
  284.         dec    ax
  285.         push    ax
  286.         xor    ax,ax        ;from column 0
  287.         push    ax
  288.         mov    al,scr_window_top_;leave top line alone
  289.         push    ax
  290.         mov    al,1
  291.         push    ax        ;scroll by 1
  292.         call    scr_scrup_    ;do the scroll
  293.         add    sp,10        ;clear arge
  294.         ret
  295.  
  296. ;    SCR_SCRUP_        Scroll the screen up. The window is scrolled
  297. ;                up nline lines. A zero nline will clear the
  298. ;                window. Top left of the screen in 0,0.
  299.  
  300. ;            Usage: scr_scrup(nline,fromrow,fromcol,torow,tocol);
  301.  
  302.         public    scr_scrup_
  303. scr_scrup_:    push    bp
  304.         mov    bp,sp
  305.         mov    al,[bp+4]    ;number of lines
  306.         mov    ch,[bp+6]    ;starting row
  307.         mov    cl,[bp+8]    ;starting column
  308.         mov    dh,[bp+10]    ;ending row
  309.         mov    dl,[bp+12]    ;ending column
  310.         mov    bh,scr_attr_    ;current attribute
  311.         mov    ah,scrollup
  312.         int    video        ;do the scroll
  313.         pop    bp
  314.         ret
  315.  
  316.  
  317. ;    SCR_SCDN_        scroll all but the top lines down one.
  318.  
  319. ;                Usage:    scr_scdn();
  320.  
  321.         public    scr_scdn_
  322. scr_scdn_:
  323.         mov    ax,scr_cols_    ;need last column of screen
  324.         dec    ax
  325.         push    ax
  326.         mov    ax,scr_rows_    ;scroll through last line
  327.         dec    ax
  328.         push    ax
  329.         xor    ax,ax        ;from column 0
  330.         push    ax
  331.         mov    al,scr_window_top_;leave top lines alone
  332.         push    ax
  333.         mov    al,1
  334.         push    ax        ;scroll by 1
  335.         call    scr_scrdn_    ;do the scroll
  336.         add    sp,10        ;clear arge
  337.         ret
  338.  
  339. ;    SCR_SCRDN_        scroll the screen down. the window is scrolled
  340. ;                down nline lines. A zero nline will clear the
  341. ;                window. Top left of the screen in 0,0.
  342.  
  343. ;            Usage: scr_scrdn(nline,fromrow,fromcol,torow,tocol);
  344.  
  345.         public    scr_scrdn_
  346. scr_scrdn_:    push    bp
  347.         mov    bp,sp
  348.         mov    al,[bp+4]    ;number of lines
  349.         mov    ch,[bp+6]    ;starting row
  350.         mov    cl,[bp+8]    ;starting column
  351.         mov    dh,[bp+10]    ;ending row
  352.         mov    dl,[bp+12]    ;ending column
  353.         mov    bh,scr_attr_    ;current attribute
  354.         mov    ah,scrolldn
  355.         int    video        ;do the scroll
  356.         pop    bp
  357.         ret
  358.  
  359.  
  360. ;    SCR_CO_            write a character to the screen. this
  361. ;                routine increments the cursor position
  362. ;                after writing. normal C88 puts and printf
  363. ;                statements can also be used to write to the
  364. ;                screen.
  365.  
  366. ;                Usage:    scr_co_(character);
  367.  
  368.         public    scr_co_
  369. scr_co_:                    ; standard console output
  370.         push    bp
  371.         mov    bp,sp
  372.         mov    al,[bp+4]    ;character to write
  373.         mov    bh,scr_page_
  374.         mov    ah,wtty        ;use tty write routine
  375.         int    video
  376.         pop    bp
  377.         ret
  378.  
  379.  
  380. ;    SCR_CI_            keyboard input. function and soft keys are
  381. ;                translated. see equates for values.
  382.  
  383. ;                Usage:    character = scr_ci();
  384.  
  385.         public    scr_ci_
  386. scr_ci_:                ;return the next character
  387.                     ; translate if necessary
  388.         push    bp
  389.         mov    ah,cicode    ;ask for a keyboard character
  390.         int    keyboard
  391.         cmp    al,0
  392.         jne    not_special
  393.         mov    bx, offset convert    ; convert special key
  394. ci_loop:
  395.         cmp    byte[bx],0
  396.         jz    got_it
  397.         cmp    ah, byte[bx]
  398.         je    got_it
  399.         add    bx,2
  400.         jmp    ci_loop
  401. got_it:        inc    bx
  402.         mov    al,[bx]
  403.         mov    ah,0
  404.         pop    bp
  405.         ret
  406. not_special:    mov    ah,0
  407.         pop    bp
  408.         ret
  409.  
  410.  
  411. ;    SCR_CSTS_        return character if any available. otherwise
  412. ;                return zero.
  413.  
  414. ;                Usage:    character = scr_csts();
  415.  
  416.         public    scr_csts_
  417. scr_csts_:                ;return coded character if any available
  418.         push    bp
  419.         mov    ah,cstscode
  420.         int    keyboard
  421.         mov    ax,0
  422.         jz    csts_over
  423.         call    scr_ci_        ;get the coded character
  424. csts_over:    pop    bp
  425.         ret
  426.  
  427.  
  428. ;    SCR_SET_CURSOR_        does nothing. needed by SEE.
  429.  
  430.  
  431.         public    scr_set_cursor_
  432. scr_set_cursor_:            ; set the visible cursor to the
  433.                     ; current position
  434.         ret
  435.  
  436.  
  437.  
  438. ;    SCR_SINP_        screen input (read character from the screen).
  439.  
  440. ;                Usage:    character = scr_sinp();
  441.  
  442.         public    scr_sinp_
  443. scr_sinp_:
  444.         push    bp        ;save the registers
  445.         mov    bh,scr_page_
  446.         mov    ah,readch    ;code to read a character
  447.         int    video        ;al is letter, ah=attributes
  448.         or    al,al        ;zero returned instead of blank in
  449.                     ;graphics mode
  450.         jnz    ret_ch
  451.         mov    al,' '
  452. ret_ch:        mov    ah,0        ;kill the attributes
  453.         pop    bp
  454.         ret
  455.  
  456.  
  457.  
  458.  
  459.  
  460. ;    SCR_CURSOFF_        turn cursor off.
  461.  
  462. ;                Usage:    scr_cursoff();
  463.  
  464.         public    scr_cursoff_
  465. scr_cursoff_:
  466.         push    bp        ;save registers
  467.         cmp    scr_mode_,4    ;see if graphics
  468.         jc    text_coff
  469.         cmp    scr_mode_,7
  470.         jnz    no_cur
  471. text_coff:
  472.         mov    cx,0f00h    ;should turn cursor off
  473. new_cur:    mov    ah,curtype    ;set a new cursor type
  474.         int    video
  475. no_cur:        pop    bp
  476.         ret
  477.  
  478.  
  479.  
  480.  
  481.  
  482. ;    SCR_CURSON_        turn cursor back on.
  483.  
  484. ;                Usage:    scr_curson();
  485.  
  486.         public    scr_curson_
  487. scr_curson_:
  488.         push    bp
  489.         mov    cx,0c0dh    ;assume monocrome
  490.         cmp    scr_mode_,7    ;true is mono
  491.         jz    new_cur        ;set it
  492.         mov    cx,0607h    ;assume color card in text mode
  493.         cmp    scr_mode_,4    ;color text is 0 to 3
  494.         jc    new_cur
  495.         pop    bp        ;do nothing if in graphics mode
  496.         ret
  497.  
  498.  
  499.  
  500. ;    SCR_MARK  --  mark the current character on the screen.
  501. ;              Used to delimit block areas in SEE. Just write
  502. ;              an X or something if reverse video is not available.
  503. ;              Usage:   scr_mark(current character);
  504.  
  505.     public    scr_mark_
  506. scr_mark_:                    ; mark the passed char,
  507.                         ; cursor does not advance
  508.         push    bp
  509.         mov    al,219            ;just write a block character
  510.         mov    bl,scr_attr_        ;normal attributes
  511.         mov    cx,1            ; one character
  512.         mov    bh,scr_page_        ;page number
  513.         mov    ah,writeach        ;write char and attr
  514.         int    video            ;write character and attributes
  515.         pop    bp
  516.         ret
  517.  
  518.  
  519. ;    the following routine is not used by either SEE or D88.
  520.  
  521.  
  522. ;    SCR_APUTS_        write a string and attributes to the screen.
  523. ;                the cursor is moved normally
  524.  
  525. ;                Usage:  acr_aputs("Print This",attribute);
  526. ;                attribute is BRGBIRGB
  527. ;                         | | | |
  528. ;                         | | | color for letter. 7 is white
  529. ;                         | | intensity for letter
  530. ;                         | color for background. 0 is black
  531. ;                         blinking
  532.  
  533.         public scr_aputs_
  534. scr_aputs_:
  535.         push    bp
  536.         mov    bp,sp
  537.         mov    ah,readcur    ;see where we are
  538.         mov    bh,scr_page_
  539.         int    video        ;dx is cursor location, bh is page
  540.         mov    si,[bp+4]    ;string pointer
  541.         mov    cx,1        ;number of characters to write
  542.         mov    bl,[bp+6]    ;attribute
  543. naputs:        cld
  544.         lodsb            ;next character to write
  545.         or    al,al        ;zero at end
  546.         jz    eaputs
  547.         cmp    al,10        ;look for LF
  548.         jnz    normal_ap
  549. ap_scroll:    mov    bp,sp        ;reset pointer to next char
  550.         mov    [bp+4],si
  551.         mov    al,13        ;use tty output to scroll screen
  552.         mov    ah,wtty
  553.         int    video        ;write cr,lf
  554.         mov    ah,wtty
  555.         mov    al,10
  556.         int    video
  557.         pop    bp
  558.         jmp    scr_aputs_    ;start over
  559. normal_ap:
  560.         mov    bh,scr_page_    ;page number
  561.         mov    ah,writeach    ;write char and attr
  562.         int    video        ;write character and attributes
  563.         inc    dl        ;next column
  564.         cmp    dl,crt_cols    ;see if wrapping around
  565.         jc    set_loc
  566.         mov    dl,0        ;at start of column
  567.         inc    dh        ;at next row
  568.         cmp    dh,byte scr_rows_;see if need a scroll
  569.         jc    set_loc
  570.         jmp    ap_scroll    ;do a scroll up
  571. set_loc:    mov    ah,setcur    ;move the cursor
  572.         int    video
  573.         jmp    naputs
  574. eaputs:        pop    bp
  575.         ret
  576.  
  577.